/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.wdb;

import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author vacoor
 */
public class WebExplorer {
    /*
    track
    -----------
    列表
    get
    http://runnable.com/api/-/users/me/runnables/U-ObTpvSDIMlgUIr/files?path=%2F&containerId=U-ObTpvSDIMlgUIr&content=true

    -------------------
    查看 get
    http://runnable.com/api/-/users/me/runnables/U-ObTpvSDIMlgUIr/files/528e941c9aa2cc1127000217
    {
    "_id": "528e941c9aa2cc1127000217",
    "name": 'text.java',
    "content": ""
    "path": ""
    "dir": false,
    default: false
    }
    -----------
    POST
    http://runnable.com/api/-/users/me/runnables/U-ObTpvSDIMlgUIr/files
    {"name":"ookx","dir":false,"path":"/jj","content":" ","containerId":"U-ObTpvSDIMlgUIr","type":"file"}
    {"name":"ookx","path":"/jj","content":" ","dir":false,"_id":"53e3a0db1cf4499b48efa98c","default":false}
    _id: "53e3a1c436520e1a41918c07"
content: " "
default: false
dir: true
name: "df"
path: "/df"
    -------
    修改
    patch
    http://runnable.com/api/-/users/me/runnables/U-ObTpvSDIMlgUIr/files/53e39bb1c2a7f3ab2c2a28af
    {content:''}
    //
    rename
    PATCH
    http://runnable.com/api/-/users/me/runnables/U-ObTpvSDIMlgUIr/files/53e39b9cc2a7f3ab2c2a28a7
    {name:''}
    ------
    DELETE
    http://runnable.com/api/-/users/me/runnables/U-ObTpvSDIMlgUIr/files/53e39c743204c71539673ca3
     */
    public void trees(String pathHash) {
        /*
                    https://api.github.com/repos/jonmiles/bootstrap-treeview/git/trees/master?recursive=true
        {
            sha: ''
            tree: [
                {
                    mode: '100644',
                    type: 'tree',
                    path: 'index.html',
                    sha: ''
                    url: ''
                    size:
                }

            ]
        }

         */
    }
    public static void main(String[] args) {
        File root = new File("/");
        String basePath = root.getAbsolutePath();
        File[] files = root.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return !file.isHidden();
            }
        });
        Arrays.sort(files, new Comparator<File>() {
            @Override
            public int compare(File file, File file2) {
                if (file == file2) {
                    return 0;
                }
                if (file != null && file2 == null) {
                    return 1;
                }
                if (file == null && file2 != null) {
                    return -1;
                }
                if (file.isDirectory() != file2.isDirectory()) {
                    return file.isDirectory() ? -1 : 1;
                }
                return file.getName().compareTo(file2.getName());
            }
        });
        for (File file : files) {
            System.out.println(file.getAbsolutePath().substring(basePath.length()));
        }
    }
}
